package com.wizhong.os.printimage;

import java.util.Map;

import android.support.v4.util.ArrayMap;
import android.text.TextUtils;

public class PrintAttributes {
	private String mIjsServer;
    private MediaSize mMediaSize;
    private Resolution mResolution;
    private int mColorMode;
    PrintAttributes() {
        /* hide constructor */
    }
    
    /**
     * Gets the media size.
     *
     * @return The media size or <code>null</code> if not set.
     */
    public MediaSize getMediaSize() {
        return mMediaSize;
    }
    /**
     * Sets the media size.
     *
     * @param The media size.
     *
     * @hide
     */
    public void setMediaSize(MediaSize mediaSize) {
        mMediaSize = mediaSize;
    }
    /**
     * Gets the resolution.
     *
     * @return The resolution or <code>null</code> if not set.
     */
    public Resolution getResolution() {
        return mResolution;
    }

    /**
     * Sets the resolution.
     *
     * @param The resolution.
     *
     * @hide
     */
    public void setResolution(Resolution resolution) {
        mResolution = resolution;
    }
    /**
     * Gets the color mode.
     *
     * @return The color mode or zero if not set.
     *
     * @see #COLOR_MODE_COLOR
     * @see #COLOR_MODE_MONOCHROME
     */
    public int getColorMode() {
        return mColorMode;
    }
    public static final class MediaSize {
		private static final String LOG_TAG = "MediaSize";
        private static final Map<String, MediaSize> sIdToMediaSizeMap =
                new ArrayMap<String, MediaSize>();
        private final String mId;
        /**@hide */
        public final String mLabel;
        /**@hide */
        public final int mLabelResId;
        private final int mWidthMils;
        private final int mHeightMils;

		 /** North America Index Card 3x5 media size: 3" x 5" (76mm x 127mm) */
		 public static final MediaSize NA_INDEX_3X5 =
		         new MediaSize("NA_INDEX_3X5", R.string.mediasize_na_index_3x5, 3000, 5000);
		 /** North America Index Card 4x6 media size: 4" x 6" (102mm x 152mm) */
		 public static final MediaSize NA_INDEX_4X6 =
		         new MediaSize("NA_INDEX_4X6",
		                 R.string.mediasize_na_index_4x6, 4000, 6000);
		 /** North America Index Card 5x8 media size: 5" x 8" (127mm x 203mm) */
		 public static final MediaSize NA_INDEX_5X8 =
		         new MediaSize("NA_INDEX_5X8",
		                 R.string.mediasize_na_index_5x8, 5000, 8000);
        
		public MediaSize(String id, int labelResId, int widthMils, int heightMils) {
			if (TextUtils.isEmpty(id)) {
				throw new IllegalArgumentException("id cannot be empty.");
			}
			if (labelResId <= 0) {
				throw new IllegalArgumentException(
						"labelResId must be greater than zero.");
			}
			if (widthMils <= 0) {
				throw new IllegalArgumentException("widthMils "
						+ "cannot be less than or equal to zero.");
			}
			if (heightMils <= 0) {
				throw new IllegalArgumentException("heightMils "
						+ "cannot be less than or euqual to zero.");
			}
            mId = id;
            mLabelResId = labelResId;
            mWidthMils = widthMils;
            mHeightMils = heightMils;
            mLabel = null;
			// Build this mapping only for predefined media sizes.
			sIdToMediaSizeMap.put(mId, this);
		}
		
	}
	
    /**
     * This class specifies a supported resolution in DPI (dots per inch).
     * Resolution defines how many points with different color can be placed
     * on one inch in horizontal or vertical direction of the target media.
     * For example, a printer with 600 DPI can produce higher quality images
     * the one with 300 DPI resolution.
     */
    public static final class Resolution {
        private final String mId;
        private final String mLabel;
        private final int mHorizontalDpi;
        private final int mVerticalDpi;

        /**
         * Creates a new instance.
         *
         * @param id The unique resolution id. It is unique amongst other resolutions
         *        supported by the printer.
         * @param label The <strong>localized</strong> human readable label.
         * @param horizontalDpi The horizontal resolution in DPI (dots per inch).
         * @param verticalDpi The vertical resolution in DPI (dots per inch).
         *
         * @throws IllegalArgumentException If the id is empty or the label is empty
         * or the horizontalDpi is less than or equal to zero or the verticalDpi is
         * less than or equal to zero.
         */
        public Resolution(String id, String label, int horizontalDpi, int verticalDpi) {
            if (TextUtils.isEmpty(id)) {
                throw new IllegalArgumentException("id cannot be empty.");
            }
            if (TextUtils.isEmpty(label)) {
                throw new IllegalArgumentException("label cannot be empty.");
            }
            if (horizontalDpi <= 0) {
                throw new IllegalArgumentException("horizontalDpi "
                        + "cannot be less than or equal to zero.");
            }
            if (verticalDpi <= 0) {
                throw new IllegalArgumentException("verticalDpi"
                       + " cannot be less than or equal to zero.");
            }
            mId = id;
            mLabel = label;
            mHorizontalDpi = horizontalDpi;
            mVerticalDpi = verticalDpi;
        }

        /**
         * Gets the unique resolution id. It is unique amongst other resolutions
         * supported by the printer.
         * <p>
         * This id is defined by the client that generated the resolution
         * instance and should not be interpreted by other parties.
         * </p>
         *
         * @return The unique resolution id.
         */
        public String getId() {
            return mId;
        }

        /**
         * Gets the resolution human readable label.
         *
         * @return The human readable label.
         */
        public String getLabel() {
            return mLabel;
        }

        /**
         * Gets the horizontal resolution in DPI (dots per inch).
         *
         * @return The horizontal resolution.
         */
        public int getHorizontalDpi() {
            return mHorizontalDpi;
        }

        /**
         * Gets the vertical resolution in DPI (dots per inch).
         *
         * @return The vertical resolution.
         */
        public int getVerticalDpi() {
            return mVerticalDpi;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            Resolution other = (Resolution) obj;
            if (mHorizontalDpi != other.mHorizontalDpi) {
                return false;
            }
            if (mVerticalDpi != other.mVerticalDpi) {
                return false;
            }
            return true;
        }

        @Override
        public String toString() {
            StringBuilder builder = new StringBuilder();
            builder.append("Resolution{");
            builder.append("id: ").append(mId);
            builder.append(", label: ").append(mLabel);
            builder.append(", horizontalDpi: ").append(mHorizontalDpi);
            builder.append(", verticalDpi: ").append(mVerticalDpi);
            builder.append("}");
            return builder.toString();
        }
    }
}
